<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: show.phtml 5116 2010-08-30 03:16:31Z huuphuoc $
 * @since		2.0.0
 */
?>
<div class="t_news_newest">
<?php if ($this->articles) : ?>
	<ul class="newest">
		<?php $i = 0; foreach ($this->articles as $article) : $i++; ?>
		<li style="<?php if ($i > 1) echo 'display: none;'; ?>" class="clearfix article_<?php echo $i; ?>">
			<?php if ($article->image_square) : ?>
			<div class="image">
				<a href="<?php echo $this->url($article->getProperties(), 'news_article_details'); ?>"><img src="<?php echo $article->image_medium; ?>" /></a>
			</div>
			<?php endif; ?>
			
			<h2><a href="<?php echo $this->url($article->getProperties(), 'news_article_details'); ?>"><?php echo $article->title; ?></a></h2>
			<div class="content">
				<cite><?php echo $this->dateFormatter()->diff(strtotime($article->created_date), $this->dateFormat); ?></cite>
                		<div><?php echo $article->description; ?></div>
			</div>
		</li>
		<?php endforeach; ?>
	</ul>
	<p class="dots">
		<span class="newest_news_prev"></span>	
		<?php if ($i > 0): ?>
			<span class="singleDot active" id="dot_1"></span>
		<?php endif; ?>
		<?php if ($i > 1): ?>
			<?php for($j = 2; $j <= $i; $j++): ?>
				<span class="singleDot" id="dot_<?php echo $j; ?>"></span>
			<?php endfor; ?>
		<?php endif; ?>
		<span class="newest_news_next"></span>	
	</p>
	<script type="text/javascript">
		$(document).ready(function (){
			var dotsCounter = $('.singleDot').size();
			
			$('.singleDot').click(function(){
				var actElIndex = parseInt($(this).attr('id').substr(4,5));
				//arrows
				$('.newest_news_prev').css('visibility','visible');
				$('.newest_news_next').css('visibility','visible');				
				if(actElIndex == 1) 
					$('.newest_news_prev').css('visibility','hidden');
				if(actElIndex == dotsCounter) 
					$('.newest_news_next').css('visibility','hidden');
				//articles
				$('ul.newest li.article_'+actElIndex).show();
				$('ul.newest li').not('.article_'+actElIndex).hide();
				//dots
				$('div.t_news_newest .dots span').removeClass('active');
				$(this).addClass('active')
			});
			
			$('.newest_news_prev').click(function(){
				$('.newest_news_next').css('visibility','visible');
				var actElIndex = parseInt($('.t_news_newest .dots .active').attr('id').substr(4,5));
				$('.t_news_newest .dots .active').prev().click();
				if(actElIndex+1 == dotsCounter) {
					$('.newest_news_prev').css('visibility','hidden');
				}
			});
			
			$('.newest_news_next').click(function(){
				$('.newest_news_prev').css('visibility','visible');
				var actElIndex = parseInt($('.t_news_newest .dots .active').attr('id').substr(4,5));
				$('.t_news_newest .dots .active').next().click();
				if(actElIndex+1 == dotsCounter) {
					$('.newest_news_next').css('visibility','hidden');
				}
			});
		});
	</script>
	<?php endif; ?>
</div>
